<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Dialog 对话框 | MyWeb 4.x</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="icon" href="/my/favicon.ico">
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?c4e5f73318b5cb0c389e3d9a05f831cc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
    <meta name="description" content="基于Vue + ElementUI 的web项目工程框架，专注于公检法行业中台系统快速搭建，框架已在多个项目实战检验。">
    <link rel="preload" href="/my/assets/css/0.styles.d7ae9199.css" as="style"><link rel="preload" href="/my/assets/js/app.2b2365a7.js" as="script"><link rel="preload" href="/my/assets/js/535.c100cd07.js" as="script"><link rel="preload" href="/my/assets/js/1270.04ee1493.js" as="script"><link rel="preload" href="/my/assets/js/1025.8afc0690.js" as="script">
    <link rel="stylesheet" href="/my/assets/css/0.styles.d7ae9199.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/my/" class="home-link router-link-active"><img src="/my/img/logo.png" alt="MyWeb 4.x" class="logo"> <span class="site-name can-hide">MyWeb 4.x</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Basic</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Form</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Data</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Notice</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Navigation</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Others</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/my/element/backtop.html" class="sidebar-link">Backtop 回到顶部</a></li><li><a href="/my/element/calendar.html" class="sidebar-link">Calendar calendar</a></li><li><a href="/my/element/card.html" class="sidebar-link">Card 卡片</a></li><li><a href="/my/element/carousel.html" class="sidebar-link">Carousel 走马灯</a></li><li><a href="/my/element/collapse.html" class="sidebar-link">Collapse 折叠面板</a></li><li><a href="/my/element/dialog.html" aria-current="page" class="active sidebar-link">Dialog 对话框</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/element/dialog.html#基本用法" class="sidebar-link">基本用法</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#自定义内容" class="sidebar-link">自定义内容</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#嵌套的-dialog" class="sidebar-link">嵌套的 Dialog</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#居中布局" class="sidebar-link">居中布局</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#attributes" class="sidebar-link">Attributes</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#slot" class="sidebar-link">Slot</a></li><li class="sidebar-sub-header"><a href="/my/element/dialog.html#events" class="sidebar-link">Events</a></li></ul></li><li><a href="/my/element/divider.html" class="sidebar-link">Divider 分割线</a></li><li><a href="/my/element/drawer.html" class="sidebar-link">Drawer 抽屉</a></li><li><a href="/my/element/image.html" class="sidebar-link">Image 图片</a></li><li><a href="/my/element/infiniteScroll.html" class="sidebar-link">InfiniteScroll 无限滚动</a></li><li><a href="/my/element/popconfirm.html" class="sidebar-link">Popconfirm 气泡确认框</a></li><li><a href="/my/element/popover.html" class="sidebar-link">Popover 弹出框</a></li><li><a href="/my/element/timeline.html" class="sidebar-link">Timeline 时间线</a></li><li><a href="/my/element/tooltip.html" class="sidebar-link">Tooltip 文字提示</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="dialog-对话框"><a href="#dialog-对话框" class="header-anchor">#</a> Dialog 对话框</h1> <p>在保留当前页面状态的情况下，告知用户并承载相关操作。</p> <h2 id="基本用法"><a href="#基本用法" class="header-anchor">#</a> 基本用法</h2> <p>Dialog 弹出一个对话框，适合需要定制性更大的场景。</p> <!----><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p><code>before-close</code> 仅当用户通过点击关闭图标或遮罩关闭 Dialog 时起效。如果你在 <code>footer</code> 具名 slot 里添加了用于关闭 Dialog 的按钮，那么可以在按钮的点击回调函数里加入 <code>before-close</code> 的相关逻辑。</p></div> <h2 id="自定义内容"><a href="#自定义内容" class="header-anchor">#</a> 自定义内容</h2> <p>Dialog 组件的内容可以是任意的，甚至可以是表格或表单，下面是应用了 Element Table 和 Form 组件的两个样例。</p> <!----><h2 id="嵌套的-dialog"><a href="#嵌套的-dialog" class="header-anchor">#</a> 嵌套的 Dialog</h2> <p>如果需要在一个 Dialog 内部嵌套另一个 Dialog，需要使用 <code>append-to-body</code> 属性。</p> <!----><h2 id="居中布局"><a href="#居中布局" class="header-anchor">#</a> 居中布局</h2> <p>标题和底部可水平居中</p> <!----><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>Dialog 的内容是懒渲染的，即在第一次被打开之前，传入的默认 slot 不会被渲染到 DOM 上。因此，如果需要执行 DOM 操作，或通过 <code>ref</code> 获取相应组件，请在 <code>open</code> 事件回调中进行。</p></div> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>如果 <code>visible</code> 属性绑定的变量位于 Vuex 的 store 内，那么 <code>.sync</code> 不会正常工作。此时需要去除 <code>.sync</code> 修饰符，同时监听 Dialog 的 <code>open</code> 和 <code>close</code> 事件，在事件回调中执行 Vuex 中对应的 mutation 更新 <code>visible</code> 属性绑定的变量的值。</p></div> <h2 id="attributes"><a href="#attributes" class="header-anchor">#</a> Attributes</h2> <table><thead><tr><th>参数</th> <th>说明</th> <th>类型</th> <th>可选值</th> <th>默认值</th></tr></thead> <tbody><tr><td>visible</td> <td>是否显示 Dialog，支持 .sync 修饰符</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>title</td> <td>Dialog 的标题，也可通过具名 slot （见下表）传入</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>width</td> <td>Dialog 的宽度</td> <td>string</td> <td>—</td> <td>50%</td></tr> <tr><td>fullscreen</td> <td>是否为全屏 Dialog</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>top</td> <td>Dialog CSS 中的 margin-top 值</td> <td>string</td> <td>—</td> <td>15vh</td></tr> <tr><td>modal</td> <td>是否需要遮罩层</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>modal-append-to-body</td> <td>遮罩层是否插入至 body 元素上，若为 false，则遮罩层会插入至 Dialog 的父元素上</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>append-to-body</td> <td>Dialog 自身是否插入至 body 元素上。嵌套的 Dialog 必须指定该属性并赋值为 true</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>lock-scroll</td> <td>是否在 Dialog 出现时将 body 滚动锁定</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>custom-class</td> <td>Dialog 的自定义类名</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>close-on-click-modal</td> <td>是否可以通过点击 modal 关闭 Dialog</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>close-on-press-escape</td> <td>是否可以通过按下 ESC 关闭 Dialog</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>show-close</td> <td>是否显示关闭按钮</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>before-close</td> <td>关闭前的回调，会暂停 Dialog 的关闭</td> <td>function(done)，done 用于关闭 Dialog</td> <td>—</td> <td>—</td></tr> <tr><td>center</td> <td>是否对头部和底部采用居中布局</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>destroy-on-close</td> <td>关闭时销毁 Dialog 中的元素</td> <td>boolean</td> <td>—</td> <td>false</td></tr></tbody></table> <h2 id="slot"><a href="#slot" class="header-anchor">#</a> Slot</h2> <table><thead><tr><th>name</th> <th>说明</th></tr></thead> <tbody><tr><td>—</td> <td>Dialog 的内容</td></tr> <tr><td>title</td> <td>Dialog 标题区的内容</td></tr> <tr><td>footer</td> <td>Dialog 按钮操作区的内容</td></tr></tbody></table> <h2 id="events"><a href="#events" class="header-anchor">#</a> Events</h2> <table><thead><tr><th>事件名称</th> <th>说明</th> <th>回调参数</th></tr></thead> <tbody><tr><td>open</td> <td>Dialog 打开的回调</td> <td>—</td></tr> <tr><td>opened</td> <td>Dialog 打开动画结束时的回调</td> <td>—</td></tr> <tr><td>close</td> <td>Dialog 关闭的回调</td> <td>—</td></tr> <tr><td>closed</td> <td>Dialog 关闭动画结束时的回调</td> <td>—</td></tr></tbody></table></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/my/element/collapse.html" class="prev">
        Collapse 折叠面板
      </a></span> <span class="next"><a href="/my/element/divider.html">
        Divider 分割线
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/my/assets/js/app.2b2365a7.js" defer></script><script src="/my/assets/js/535.c100cd07.js" defer></script><script src="/my/assets/js/1270.04ee1493.js" defer></script><script src="/my/assets/js/1025.8afc0690.js" defer></script>
  </body>
</html>
